package com.cloud.base.thread.condition;

import lombok.SneakyThrows;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ConditionMain {
    public static void main(String[] args) throws InterruptedException {
        Lock lock = new ReentrantLock();
        Condition condition = lock.newCondition();
        new Thread(() -> {
            ConditionMain.del(lock,condition);
        }).start();
        Thread.sleep(5000);

    }

    @SneakyThrows
    public static void del( Lock lock,Condition condition) {
        lock.lock();
        System.out.println("del执行开始:" + Thread.currentThread().getName());
        condition.await();
        System.out.println("del执行结束:" + Thread.currentThread().getName());
        condition.signalAll();
        lock.unlock();
    }
}
